#include "compfwk/CEntityServer.h"

#include "compfwk/compfwk.h"
#include "compfwk/IEntity.h"

namespace compfwk
{
    CEntityServer& CEntityServer::Instance( )
    {
        static CEntityServer instance;
        return instance;
    }

    CEntityServer::CEntityServer( ) : m_hm_ents( )
    {
    }

    CEntityServer::~CEntityServer( )
    {
        /*CHMEnts::iterator it( m_hm_ents.begin( ) );
        CHMEnts::iterator end( m_hm_ents.end( ) );

        //HACK NEED TO BE FIXED
        for( ; it != end; ++it )
        {
           delete it->second;
        }*/
    }

    void CEntityServer::AddEntity( IEntity* ap_ent )
    {
        if( ap_ent )
        {
            m_hm_ents[ ap_ent->GetEntityId( ) ] = ap_ent;
        }
    }

    IEntity* CEntityServer::Find( int a_eid )
    {
        CHMEnts::iterator result( m_hm_ents.find( a_eid ) );
        if( result != m_hm_ents.end( ) )
            return result->second;
        else
            return 0;
    }
}